﻿using System;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;

namespace SDT.CrawlSystem.Tools
{
    public partial class Checker : Form
    {
        public Checker()
        {
            InitializeComponent();
        }

        private void btnTest_Click(object sender, EventArgs e)
        {
            var total = 0;
            var b = new StringBuilder("Found ");

            var patterns = txtRegEx.Text.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

            foreach (var p in patterns)
            {
                var col = Regex.Matches(txtInput.Text, p);

                foreach (Match m in col)
                {
                    if (m.Success)
                    {
                        total++;
                        b.Append('@').Append(m.Index).Append(" = ").AppendLine(m.Value);
                    }
                }
            }

            b.Insert("Found ".Length, total.ToString() + " matches\r\n\r\n");
            txtResult.Text = b.ToString();
        }
    }
}